<?php
declare(strict_types=1);

namespace App\Command;

use App\Cache\IpAddressCache;
use App\Constant\RobotConstant;
use App\Model\Contact\Contact;
use App\Model\Players;
use App\Repository\ExampleRepository;
use App\Repository\RobotRepository;
use App\Service\GiftService;
use App\Service\RobotService;
use App\Service\UserService;
use App\Support\IpAddress;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Hyperf\DbConnection\Db;
use Psr\Container\ContainerInterface;

/**
 * @Command
 */
class TestCommand extends HyperfCommand
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;

        parent::__construct('test:command');
    }

    public function configure()
    {
        parent::configure();
        $this->setDescription('Hyperf Demo Command');
    }

    public function handle()
    {
        GiftService::PlayerGiftRankV2(1521);
        exit;
        $productId = 1003;
        $time = '2022-11-15'; // 送币开始时间
        $price = 10;   // 送了10个比
        $os = DB::table('live_charge_order')
            ->where('product_id', '=', $productId)
            ->get();
        foreach ($os as $o) {
            $userId = data_get($o, 'user_id');

            $isExist = DB::table('user_live_account_transaction')
                ->where('user_id', '=', $userId)
                ->where('source_type', '=', 'live_act'.$productId)
                ->first();
            if (!empty($isExist)) {
                continue;
            }
            $points = DB::table('talk_records_gift')
                ->join('live_gift as g', 'g.id', '=', 'talk_records_gift.gift_id')
                ->where('talk_records_gift.user_id', '=', $userId)
                ->where('talk_records_gift.created_at', '>=', $time)
                ->sum('g.price');
            info('zuofei', [$userId, $points]);
            try {
                if ($points <= $price) {
                    $jian = bcsub((string)$price, (string)$points);
                    UserService::commonTransaction($userId, -$jian, 0, 'live_act'.$productId, '过期作废');
//                } else {
//                    UserService::commonTransaction($userId, -10, 0, 'live_act'.$productId, '过期作废');
                }
            } catch (\Exception $e) {}
//            exit;
        }
        exit;
        $name = '赵家驹';
        $idnums = [];


        $r = GiftService::PlayerGiftRankV2('1485', ['page' => 1, 'page_size' => 2000]);
        print_r($r);exit;


        // $repository = di()->get(ExampleRepository::class);
        // $repository->where_case2();
    }
}
